package com.motion.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.motion.generator.entity.SecurityQusetion;
import com.motion.generator.mapper.SecurityQusetionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class SecurityQusetionServer {
    @Autowired
    SecurityQusetionMapper securityQusetionMapper;
    public List<SecurityQusetion> getSecurityQusetion(Long useId){
        return  securityQusetionMapper.selectList(new QueryWrapper<SecurityQusetion>().eq("userId",useId).orderByAsc("createTime"));
    }
    public SecurityQusetion insert(Long userId,String question,String answer){
        SecurityQusetion securityQusetion=new SecurityQusetion();
        securityQusetion.setAnswer(answer);
        securityQusetion.setQuestion(question);
        securityQusetion.setUserId(userId);
        securityQusetion.setCreateTime(LocalDateTime.now());
        securityQusetionMapper.insert(securityQusetion);
        return securityQusetion;
    }
}
